# Copyright (C) 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//tools/build:rules.bzl", "android_dynamic_library", "cc_copts", "mm_library")

mm_library(
    name = "darwin_query",
    srcs = glob(["osx/*.mm"]),
    copts = cc_copts(),
    copy_hdrs = ["query.h"],
    deps = ["//core/os/device:device_cc_proto"],
)

cc_library(
    name = "cc",
    srcs = glob(["*.cpp"]) + select({
        "//tools/build:linux": glob(["linux/query.cpp"]),
        "//tools/build:windows": glob(["windows/query.cpp"]),
        "//tools/build:darwin": [],
        "//tools/build:darwin_arm64": [],
        "//tools/build:fuchsia-arm64": glob(["fuchsia/query.cpp"]),
        "//tools/build:fuchsia-x86_64": glob(["fuchsia/query.cpp"]),
        # Android
        "//conditions:default": glob([
            "android/*.cpp",
            "android/*.h",
        ]),
    }),
    hdrs = glob(["*.h"]),
    copts = cc_copts(),
    linkopts = select({
        "//tools/build:linux": [],
        "//tools/build:darwin": [],
        "//tools/build:darwin_arm64": [],
        "//tools/build:fuchsia-arm64": [],
        "//tools/build:fuchsia-x86_64": [],
        "//tools/build:windows": [],
        # Android
        "//conditions:default": [
            "-llog",
            "-lm",
        ],
    }),
    visibility = ["//visibility:public"],
    deps = [
        "//core/cc",
        "//core/os/device:device_cc_proto",
        "@com_google_protobuf//:protobuf",
    ] + select({
        "//tools/build:darwin": [":darwin_query"],
        "//tools/build:darwin_arm64": [":darwin_query"],
        "//tools/build:fuchsia-arm64": [
            "@fuchsia_sdk//fidl/fuchsia.gpu.agis:fuchsia.gpu.agis_llcpp_cc",
            "@fuchsia_sdk//fidl/fuchsia.hwinfo:fuchsia.hwinfo_cc",
            "@fuchsia_sdk//pkg/sys_cpp",
        ],
        "//tools/build:fuchsia-x86_64": [
            "@fuchsia_sdk//fidl/fuchsia.gpu.agis:fuchsia.gpu.agis_llcpp_cc",
            "@fuchsia_sdk//fidl/fuchsia.hwinfo:fuchsia.hwinfo_cc",
            "@fuchsia_sdk//pkg/sys_cpp",
        ],
        "//conditions:default": [],
    }),
)

android_dynamic_library(
    name = "libdeviceinfo",
    visibility = ["//visibility:public"],
    exports = "libdeviceinfo.exports",
    deps = [":cc"],
)
